class Observer{
    constructor(){

    }

    update(val){
        console.log(val);
    }
}

class ObserverList{
    constructor(){
        this.observers = []
    }
    add(observer){
        this.observers.push(observer)
    }
    remove(observer){
        this.observers.splice(this.observers.indexOf(observer,1))

    }
    length(){
        return this.observers.length
    }
    get(index){
        return this.observers[index]
    }
}

class Subject{
    constructor(){
        this.observers = new ObserverList()
    }
    addObserver(observer){
        this.observers.add(observer)
    }
    removeObserver(observer){
        this.observers.remove(observer)
    }
    notify(...args){
        const len = this.observers.length()
        for(let i=0;i<len;i++){
            this.observers.get(i).update(...args)
        }
    }
}